import Vue from 'vue'
import Router from 'vue-router'
import errorPage from '@/components/errorpage';
//搜索
import search from '@/components/share/search/search';
//语音回复
import feedback from '@/components/share/feedback/feedback.vue';
import { indexRoutes } from '@/components/index/router/index.routes'
import { userRoutes } from '@/components/user/router/user.routes'
import { orderRoutes } from '@/components/order/router/order.routes'
import { contactsRoutes } from '@/components/contacts/router/contacts.routes'
import { messageRoutes } from '@/components/message/router/msg.routes'
import { mailRoutes } from '@/components/mail/router/mail.routes'
import { indexManRoutes } from '@/components/index_man/router/indexMan.routes'
import { pcRoutes } from '@/components/pc/router/pc.routes'
import { loginRoutes } from '@/components/login/router/login.routes'
import { settleRoutes } from '@/components/settle/router/settle.routes'
Vue.use(Router)


const router = new Router({
  routes: [
    //路径重定向
    {
      path: '/',
      redirect: '/index'
    },
    ...indexRoutes,
    ...userRoutes,
    ...orderRoutes,
    ...contactsRoutes,
    ...messageRoutes,
    ...mailRoutes,
    ...indexManRoutes,
    ...loginRoutes,
    ...pcRoutes,
    ...settleRoutes,
    {
      path:'/search',
      name: '搜索',
      component: search
    },
    {
      path: '/feedback',
      name: '反馈',
      component: feedback
    },
    //默认错误地址跳转页
    {
      path: '*',
      name: 'errorPage',
      component: errorPage
    }
  ]
})

//路由权限跳转控制
router.beforeEach((to, from, next) => {
  let path = to.matched.filter(v => v.meta.requireAuth);
  if (path.length) {
      // let metaName = path[0].meta.requireAuth,
      //     adminLogin = (metaName=="admin" && !cookie.getCookie('accountId')),
      //     manaLogin = (metaName=="manager" && !cookie.getCookie('managerId'));
      // if(adminLogin || manaLogin){
      //   next({
      //     path: '/login',
      //   })
      // }else{
      //   next();
      // }
  } else {
      next();
  }
})

export default router